package com.fowo.api.common.mybatis.helper;

import net.sf.jsqlparser.expression.CastExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.Function;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.statement.create.table.ColDataType;

/**
 * 分页搜索器 MySql 方言处理
 * @author yl_ls
 */
public class MySqlPageSearchSqlDialect implements PageSearchSqlDialect {
    @Override
    public Expression stringSetFieldInExpression(Expression left, Expression right) {
        return new Function().withName("FIND_IN_SET").withParameters(new ExpressionList().addExpressions(right, left));
    }

    @Override
    public Expression jsonArrayFieldInExpression(Expression left, Expression right) {
        return new Function().withName("JSON_CONTAINS").withParameters(new ExpressionList().addExpressions(
                left,
                new CastExpression().withLeftExpression(right).withType(new ColDataType("CHAR"))
        ));
    }
}
